package cz.zcu.sefler.mois.business;

import cz.zcu.sefler.mois.data.model.Monitor;

/**
 * Tato trida se stara o rizeni aplikacni logiky. Zada praci jak pro zpracovani
 * jednoho rozhovoru, tak celeho obsahu serveru super.cz.
 * 
 * @author Vojtech Sefler
 * 
 */
public class MonitorManager {

  private String dbMachine;
  private String dbDb;
  private String dbUser;
  private String dbPass;

  public MonitorManager(String dbMachine, String dbDb, String dbUser, String dbPass) {
    this.dbMachine = dbMachine;
    this.dbDb = dbDb;
    this.dbUser = dbUser;
    this.dbPass = dbPass;
  }

  /**
   * Metoda vytvori instanci tridy SuperCzArchiveSpiderAndDirigentThread, ktera
   * zajisti zpracovani serveru super.cz.
   */
  public void getWholeSuperCz() {
    SuperCzArchiveSpiderAndDirigentThread dirigent = new SuperCzArchiveSpiderAndDirigentThread(dbMachine, dbDb, dbUser, dbPass);

    /* Start instance. */
    dirigent.start();
    try {
      /* Pockame, dokud instance nedobehne do konce. */
      dirigent.join();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }

  /**
   * 
   * Metoda vytvori instanci tridy SuperCzMonitorThread, ktera zajisti
   * zpracovani jednoho rozhovoru serveru super.cz.
   * 
   * @param monitor
   */
  public void createMonitor(Monitor monitor) {
    GeneralMonitorThread newMonitorThread;
    newMonitorThread = new SuperCzMonitorThread(monitor, dbMachine, dbDb, dbUser, dbPass);
    /* Start instance. */
    newMonitorThread.start();
  }

}
